From 14d0cc5c8f8a3702b69dfdbfad9ee91adfb83cf1 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 15 May 2014 08:39:21 -0700 Subject: [PATCH] Tweaks to compareParserCache.php * Skip parsing if there is no cache entry to compare to * Mention the total number of pages with differences Change-Id: I8905ae02b4d6c414690a30aec01b11abd1e22d14 --- maintenance/compareParserCache.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/maintenance/compareParserCache.php b/maintenance/compareParserCache.php index 97fd3ffcc9..93fe6601e9 100644 --- a/maintenance/compareParserCache.php +++ b/maintenance/compareParserCache.php @@ -40,6 +40,7 @@ class CompareParserCache extends Maintenance { $totalsec = 0.0; $scanned = 0; $withcache = 0; + $withdiff = 0; while ( $pages-- > 0 ) { $row = $dbr->selectRow( 'page', '*', array( @@ -67,21 +68,22 @@ class CompareParserCache extends Maintenance { $parserOutputOld = ParserCache::singleton()->get( $page, $parserOptions ); - $t1 = microtime( true ); - $parserOutputNew = $content->getParserOutput( - $title, $revision->getId(), $parserOptions, false ); - $sec = microtime( true ) - $t1; - $totalsec += $sec; + if ( $parserOutputOld ) { + $t1 = microtime( true ); + $parserOutputNew = $content->getParserOutput( + $title, $revision->getId(), $parserOptions, false ); + $sec = microtime( true ) - $t1; + $totalsec += $sec; - $this->output( "Parsed '{$title->getPrefixedText()}' in $sec seconds.\n" ); + $this->output( "Parsed '{$title->getPrefixedText()}' in $sec seconds.\n" ); - if ( $parserOutputOld ) { $this->output( "Found cache entry found for '{$title->getPrefixedText()}'..." ); $oldHtml = trim( preg_replace( '##Us', '', $parserOutputOld->getText() ) ); $newHtml = trim( preg_replace( '##Us', '',$parserOutputNew->getText() ) ); $diff = wfDiff( $oldHtml, $newHtml ); if ( strlen( $diff ) ) { $this->output( "differences found:\n\n$diff\n\n" ); + ++$withdiff; } else { $this->output( "No differences found.\n" ); } @@ -91,8 +93,9 @@ class CompareParserCache extends Maintenance { } } - $ave = $scanned ? $totalsec / $scanned : 0; + $ave = $totalsec ? $totalsec / $scanned : 0; $this->output( "Checked $scanned pages; $withcache had prior cache entries.\n" ); + $this->output( "Pages with differences found: $withdiff\n" ); $this->output( "Average parse time: $ave sec\n" ); } } -- 2.20.1